home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / expressionEdCallbacks.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  49.0 KB  |  1,910 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  ==================== expressionEdCallbacks.mel ==========
  22. //
  23. //  SYNOPSIS
  24. //
  25. //  CONTENTS
  26. //        (The procs are in the file in the order listed here.)
  27. //
  28. //    Expression Editor Procedures:
  29. //
  30. //
  31. //  Expression Editor UI control callbacks:
  32. //
  33. //    EEapplyCB                Create/Edit the expression.
  34. //    EEdeleteCB                Delete the expression.
  35. //    EErestoreCB                Restore the expression.
  36. //    EEclearCB                Clear the text area.
  37. //  EEcloseCB                Close the window.
  38. //    EEanimatedCB            Callback for animated checkbox.
  39. //    EEunitConversionCB        Callback for unit conversion radio group.
  40. //    EEexprNameTextCB        Callback for expression name textfield.
  41. //    EEdefaultNodeCB            Callback for default node name textfield.
  42. //    EEselectedNodeAttrCB    Callback for node-attribute name textfield.
  43. //    EEnewExpressionCB        Callback for "New Expression" Button.
  44. //    EEnodeListCB            User selected something (sngl click) in node list.
  45. //    EEnodeListDblClickCB    User selected something (dbl click) in node list
  46. //    EEattrListCB            User selected something (sngl click)in attr list.
  47. //    EEattrListDblClickCB    User selected something (dbl click) in attr list.
  48. //    EEselectFilterCB        User selected something in the Select menu.
  49. //    EEobjFilterCB            User selected something in the Obj Filter menu.
  50. //    EEattrFilterCB            User selected something in the Attr Filter menu.
  51. //  EEeditorCB                User selected something in editors opt menu.
  52. //    EErulesCB                User selected a rules radio button.
  53. //    EEmathFuncCB()          User selected a math function menu.
  54. //    EEvectFuncCB()            User selected a vector function menu.
  55. //    EEconvFuncCB()            User selected a conversion function menu.
  56. //    EEarrayFuncCB()            User selected a array function menu.
  57. //    EErandFuncCB()          User selected a random number function menu.
  58. //
  59. //    Expression Editor Message Callbacks
  60. //        These are called from TexprEdListenAction.cc
  61. //
  62. //  EEactiveListChanged       Callback for active list changed.
  63. //  EEnodeAdded             Callback for a node added to a scene.
  64. //  EEnodeRemoved             Callback for a node removed from the scene.
  65. //  EEnodeNameChanged         Callback for a node name change in the scene.
  66. //  EEattributeAdded          Callback for attribute added to selected node.
  67. //  EEattributeRemoved        Callback for attribute removed from selected node.
  68. //    EEexpressionCreated        Callback for expression created.
  69. //    EEexpressionEdited        Callback for expression edited.
  70. //    EEparticleExpressionCreated    Callback for particle expression created.
  71. //    EEparticleExpressionDeleted    Callback for particle expression deleted.
  72. //    EEparticleExpressionEdited    Callback for particle expression edited.
  73. //    EEclearExpresionEditor        Callback for file new/open to clear editor.
  74. //    EEresetExpressionEditor        Callback for file open to rebuild the editor.
  75.  
  76.  
  77. // ******************************************************************
  78. //
  79. //                    EXPRESSION EDITOR CALLBACKS
  80. //
  81. // 
  82. //  ================ EEapplyCB ================
  83. //
  84. //  SYNOPSIS
  85. //      Create the expression in the editor and connect it to
  86. //        to the current selected attribute or
  87. //        replace its current expression with the newly edited one.
  88. //
  89. //
  90. global proc EEapplyCB()
  91. {
  92.     global int $EEobjIsParticle;
  93.     global int $EEcreateMode;
  94.     global string $EEnodeMode;
  95.  
  96.     string $theText;
  97.  
  98.     // Get the value of the text and create or edit the expression node 
  99.     //
  100.     $theText = `scrollField -q -tx EEmultiText`;
  101.  
  102.     if (size($theText) == 0 && $EEcreateMode)
  103.     {
  104.         warning "Expression Editor: There's no expression to create.";
  105.         return;
  106.     }
  107.  
  108.     if (size($theText) > 0)
  109.     {
  110.         int $lastIndex = size($theText);
  111.         string $firstChar = substring($theText, 1, 1);
  112.         string $lastChar = substring($theText, $lastIndex, $lastIndex);
  113.  
  114.         // Strip the final carriage returns and spaces.
  115.         //
  116.         while ($lastChar == "\n" || $lastChar == " ")
  117.         {
  118.             if ($lastIndex == 1)
  119.             {
  120.                 $theText = "";
  121.                 break;
  122.             }
  123.             else
  124.             {
  125.                 $theText = substring($theText, 1, size($theText) - 1);
  126.                 $lastIndex = $lastIndex - 1;
  127.                 $lastChar = substring($theText, $lastIndex, $lastIndex);
  128.             }
  129.         }
  130.  
  131.         if (size($theText) == 0 && $EEcreateMode)
  132.         {
  133.             warning "Expression Editor: There's no expression to create.";
  134.             return;
  135.         }
  136.  
  137.         // If there are quotes surrounding the expression, strip 
  138.         // them 
  139.         //
  140.         if ($firstChar == "\"")
  141.         {
  142.             $theText = substring ($theText, 2, size($theText));
  143.         }
  144.         if ($lastChar == "\"")
  145.         {
  146.             $theText = substring ($theText, 1, size($theText) - 1);
  147.         }
  148.     }
  149.  
  150.     
  151.     if ($EEobjIsParticle)
  152.     {
  153.         if ($EEcreateMode)
  154.         {
  155.             EEapplyParticleExpression($theText);
  156.         }
  157.         else
  158.         {
  159.             string $objAttrName = `textFieldGrp -q -tx EEselNameT`;
  160.             string $buffer[];
  161.             tokenize($objAttrName, ".", $buffer);
  162.             // If there's no attribute selected, we are definitely
  163.             // doing a dynExprression.  If there is one selected,
  164.             // we have to find out what kind of expression it is
  165.             // connected to.
  166.             //
  167.             int $isDynExpression = 1;
  168.             if (size($buffer[1]))
  169.                 $isDynExpression = EEisDynExpression($objAttrName);
  170.  
  171.             if ($isDynExpression)
  172.                 EEapplyParticleExpression($theText);
  173.             else
  174.                 EEapplyExpression($theText);
  175.         }
  176.     }
  177.     else
  178.     {
  179.         if ($EEnodeMode == "scriptNode") 
  180.         {
  181.             EEapplyScript($theText);
  182.         } 
  183.         else 
  184.         {
  185.             EEapplyExpression($theText);
  186.         }
  187.     }
  188.  
  189. }    // EEapplyCB
  190.  
  191.  
  192.  
  193. //  ================ EErestoreCB ================
  194. //
  195. //  SYNOPSIS
  196. //      Restore the expression in the expression node to the
  197. //        editor text area.
  198. //
  199. //
  200. global proc EErestoreCB()
  201. {
  202.     global int $EEobjIsParticle;
  203.     global string $EEnodeMode;
  204.  
  205.     string $currObjAttrName;
  206.  
  207.     if ($EEnodeMode == "expression")
  208.     {
  209.         EErestoreExpression();
  210.     }
  211.     else if ($EEnodeMode == "scriptNode")
  212.     {
  213.         EErestoreScript();
  214.     }
  215.     else
  216.     {
  217.         if ($EEobjIsParticle)
  218.         {
  219.             EErestoreParticleExpression();
  220.         }
  221.         else
  222.         {
  223.             EErestoreExpression();
  224.         }
  225.     }
  226.  
  227. }    // EErestoreCB
  228.  
  229.  
  230. //  ================ EEclearCB ================
  231. //
  232. //  SYNOPSIS
  233. //      Clear the text.
  234. //
  235. //
  236. global proc EEclearCB()
  237. {
  238.     scrollField -e -tx "" EEmultiText;
  239.  
  240. }    // EEclearCB
  241.  
  242.  
  243. //  ================ EEcloseCB =================
  244. //
  245. //  SYNOPSIS
  246. //      Close the expression editor window
  247. //
  248. //
  249. global proc EEcloseCB()
  250. {
  251.     deleteUI expressionEditorWin;
  252.  
  253. }   // EEcloseCB
  254.  
  255.  
  256. //  ================ EEanimatedCB ================
  257. //
  258. //  SYNOPSIS
  259. //      Called when the animated checkbox is changed.
  260. //
  261. global proc EEanimatedCB()
  262. {
  263.     global int $EEcreateMode;
  264.     global int $EEeditedInEditor;
  265.     global string $EEcurrExpressionName;
  266.  
  267.     // If in edit mode, reset the expression animated value immediately.
  268.     //
  269.     if (!$EEcreateMode)
  270.     {
  271.         int $anFlagVal = `checkBox -q -v EEanimCBox`;
  272.         $EEeditedInEditor = 1;
  273.         evalEcho("expression -e -ae "+$anFlagVal+" "+$EEcurrExpressionName);
  274.     }
  275.  
  276. }    // EEanimatedCB
  277.  
  278.  
  279. //  ================ EEunitConversionCB ================
  280. //
  281. //  SYNOPSIS
  282. //      Called when the unit conversion radio set is changed.
  283. //
  284. global proc EEunitConversionCB(string $thePref)
  285. {
  286.     global int $EEcreateMode;
  287.     global int $EEobjIsParticle;
  288.     global int $EEeditedInEditor;
  289.     global string $EEcurrExpressionName;
  290.  
  291.     // If in edit mode, reset the expression unit conversion preference
  292.     // immediately.
  293.     //
  294.     if (!$EEcreateMode)
  295.     {
  296.         if (!$EEobjIsParticle)
  297.         {
  298.             $EEeditedInEditor = 1;
  299.             evalEcho("expression -e -uc "+$thePref+" "+$EEcurrExpressionName);
  300.         }
  301.     }
  302.  
  303. }    // EEunitConversionCB
  304.  
  305.  
  306. //  ================ EEexprNameTextCB ================
  307. //
  308. //  SYNOPSIS
  309. //      Called when the expression name textfield is changed.
  310. //
  311. global proc EEexprNameTextCB()
  312. {
  313.     global string $EEcurrExpressionName;
  314.     global string $EEcurrFileExprName[];
  315.     global int      $EEexpressionInEditor;
  316.     global int $EEcreateMode;
  317.     global int $EEcurrentEditor;
  318.     global int $EEeditedInEditor;
  319.     global string $EEnodeMode;
  320.  
  321.     string $exprName = `textField -q -tx EEexprNameT`;
  322.  
  323.     // If $exprName == "" and in edit mode, then return text field 
  324.     // to what it was
  325.     //
  326.     if( $exprName == "" && !$EEcreateMode)
  327.     {
  328.         if (size($EEcurrExpressionName) > 0)
  329.         {
  330.                textField -e -tx $EEcurrExpressionName EEexprNameT;
  331.         }
  332.            else
  333.         {
  334.                textField -e -tx "" EEexprNameT;
  335.         }
  336.         return;
  337.     }
  338.  
  339.     // If $exprName == $currExpressionName, it means either
  340.     // that the new name has already been processed, or the
  341.     // field was touched but nothing changed.  So just return.
  342.     // (The former can happen if the user does not press carriage
  343.     // return, and then selects "Apply", because there is
  344.     // no focus-out callback available in ELF.)
  345.     //
  346.     if ($exprName == $EEcurrExpressionName)
  347.         return;
  348.  
  349.     // If the name the user typed is already the name of an
  350.     // expression node then it is not valid; the EEcheckValidExprName
  351.     // proc will remove it and restore the previous name, and return
  352.     // 0.
  353.     //
  354.     int $nameValid;
  355.     if ($EEnodeMode == "scriptNode")
  356.     {
  357.         if ($nameValid = EEcheckValidScriptName($exprName)) 
  358.         {
  359.             if (!$EEcreateMode)
  360.             {
  361.                 //     If in edit mode, rename the script
  362.                 //
  363.                 $EEeditedInEditor = 1;
  364.                 $exprName = 
  365.                     evalEcho("rename "+$EEcurrExpressionName+" "+$exprName);
  366.                 
  367.                 textFieldGrp -e -tx $exprName EEselScriptNodeNameT;
  368.  
  369.                 // If the user is in a text editor mode, have to update to
  370.                 // the new expression name in the file array.
  371.                 //
  372.                 if ($EEexpressionInEditor > -1 && $EEcurrentEditor != 1)
  373.                 {
  374.                     if ($EEcurrFileExprName[$EEexpressionInEditor] == $EEcurrExpressionName)
  375.                         $EEcurrFileExprName[$EEexpressionInEditor] = $exprName;
  376.                 }
  377.  
  378.                 $EEcurrExpressionName = $exprName;
  379.                 textField -e -tx $EEcurrExpressionName EEexprNameT;
  380.  
  381.                 if (EEscriptNameExists($exprName))
  382.                     EEupdateExprList();
  383.             }
  384.         }
  385.     }
  386.     else 
  387.     {
  388.         if ($nameValid = EEcheckValidExprName($exprName))
  389.         {
  390.             // If in edit mode, rename the expression immediately.
  391.             if (!$EEcreateMode)
  392.             {
  393.                 $EEeditedInEditor = 1;
  394.                 $exprName = evalEcho("expression -e -n \""+$exprName+"\" "+$EEcurrExpressionName+"\n");
  395.  
  396.                 // If the user is in a text editor mode, have to update to
  397.                 // the new expression name in the file array, if this is
  398.                 // not a particle expression.
  399.                 //
  400.                 if ($EEexpressionInEditor > -1 && $EEcurrentEditor != 1)
  401.                 {
  402.                     if ($EEcurrFileExprName[$EEexpressionInEditor] == $EEcurrExpressionName)
  403.                         $EEcurrFileExprName[$EEexpressionInEditor] = $exprName;
  404.                 }
  405.             }
  406.             $EEcurrExpressionName = $exprName;
  407.             textField -e -tx $EEcurrExpressionName EEexprNameT;
  408.  
  409.             // If the user is in select-by-expression mode, update the
  410.             // list of expressions with the new name, if the new name
  411.             // is an existing expression.  Otherwise the user is creating
  412.             // a name for a new expression.
  413.             //
  414.             if (EEexprNameExists($exprName))
  415.                 EEupdateExprList();
  416.         }
  417.     }
  418.  
  419. }    // EEexprNameTextCB
  420.  
  421. //  ================ EEdefaultNodeCB ================
  422. //
  423. //  SYNOPSIS
  424. //      Called when the Default Object name textfield is changed.
  425. //
  426. global proc EEdefaultNodeCB()
  427. {
  428.     global int $EEcreateMode;
  429.     global int $EEeditedInEditor;
  430.     global string $EEcurrExpressionName;
  431.  
  432.     string  $newObjName;
  433.  
  434.     // Get the newly typed Object name
  435.     //
  436.        $newObjName = `textFieldGrp -q -tx EEdefNameT`;
  437.  
  438.     if (size($newObjName) == 0)
  439.     {
  440.         textFieldGrp -e -tx "" EEdefNameT;
  441.         return;
  442.     }
  443.     if (!EEisValidNodeName($newObjName))
  444.     {
  445.         textFieldGrp -e -tx "" EEdefNameT;
  446.         return;
  447.     }
  448.     if (!$EEcreateMode)
  449.     {
  450.         $EEeditedInEditor = 1;
  451.         evalEcho("expression -e -o "+$newObjName+" "+$EEcurrExpressionName+"\n");
  452.     }
  453.  
  454. }    // EEdefaultNodeCB
  455.  
  456.  
  457. //  ================ EEselectedNodeAttrCB ================
  458. //
  459. //  SYNOPSIS
  460. //      Called when the selected object.attribute name textfield 
  461. //        is changed.
  462. //
  463. global proc EEselectedNodeAttrCB()
  464. {
  465.     string $currentAttrs[];
  466.     string $nodeNames[], $names[];
  467.     int $attrListIndex;
  468.     
  469.     string $objAttrName = `textFieldGrp -q -tx EEselNameT`;
  470.     string $buffer[];
  471.     tokenize($objAttrName, ".", $buffer);
  472.     string $nodeName = $buffer[0];
  473.     string $attrName = $buffer[1];
  474.  
  475.     if (size($nodeName) == 0 && size($attrName) == 0)
  476.     {
  477.         // The textfield is empty, so deselect everything
  478.         // and clear controls.
  479.         //
  480.         EEclearAllControls();
  481.  
  482.         textScrollList -e -da EEnodeList;
  483.         textScrollList -e -da EEattrList;
  484.  
  485.         return;
  486.     }
  487.  
  488.     if (size($attrName) == 0 )
  489.     {
  490.         // There's only one name in the textfield:  start out by
  491.         // assuming it's an attribute name.
  492.         //
  493.         $attrName = $nodeName;
  494.  
  495.         // If the name is in the attribute list for the currently
  496.         // selected object, load it.
  497.         //
  498.         if ((($attrListIndex = EEattrIsInList($attrName)) > -1) ||
  499.             (($attrListIndex = EEgetAttrFromNode($attrName)) > -1))
  500.         {
  501.             EEnewSelectedAttr($attrListIndex);
  502.  
  503.             // Get the name of the current object and long name of the
  504.             // newly typed attribute for future reference.
  505.             //
  506.             $names = `textScrollList -q -si EEnodeList`;
  507.             $nodeName = $names[0];
  508.             $names = `textScrollList -q -si EEattrList`;
  509.             $attrName = $names[0];
  510.  
  511.         }
  512.         else 
  513.         {
  514.             // The name is not in the attribute list, so it must
  515.             // be an object name.  Deselect the selected attribute
  516.             // in the attribute list;  clear the controls (the obj
  517.             // name will be re-instated later); if the name is in
  518.             // the object list, make it selected, and build its
  519.             // attribute list.
  520.             //
  521.             textScrollList -e -da EEattrList;
  522.             EEclearAllControls();
  523.  
  524.             if (EEnodeIsInList($nodeName) > -1)
  525.             {
  526.                 EEnewSelectedNode($nodeName);
  527.                 $attrName = "";
  528.             }
  529.             else 
  530.             {
  531.                 // Name is not in object list. Check if it's a valid
  532.                 // object in the scene and if it is:
  533.                 // Reset the filter to all dag objs or dep nodes, rebuild
  534.                 // the object list, make the new object selected, and
  535.                 // build its attribute list.
  536.                 //
  537.                 if (EEisValidNodeName($nodeName))
  538.                 {
  539.                     EEresetFilterToAll($nodeName);
  540.                     EEnewSelectedNode($nodeName);
  541.                     $attrName = "";
  542.                 }
  543.                 else
  544.                 {
  545.                     // Reset the textfield with the current obj/attr name,
  546.                     // if there is one .
  547.                     //
  548.                     string $names[];
  549.                     $names = `textScrollList -q -si EEnodeList`;
  550.                     $nodeName = $names[0];
  551.                     $names = `textScrollList -q -si EEattrList`;
  552.                     $attrName = $names[0];
  553.                 }
  554.             }
  555.         }
  556.     }
  557.     else 
  558.     {
  559.         // User typed object.attribute 
  560.  
  561.         // Is the object currently selected in the object list?
  562.         //
  563.         $nodeNames = `textScrollList -q -si EEnodeList`;
  564.         if ($nodeName == $nodeNames[0])
  565.         {
  566.             // Make the newly typed attribute selected, if it's really
  567.             // an attribute of the currently selected object.
  568.             //
  569.             if ((($attrListIndex = EEattrIsInList($attrName)) > -1) ||
  570.                 (($attrListIndex = EEgetAttrFromNode($attrName)) > -1))
  571.             {
  572.                 EEnewSelectedAttr($attrListIndex);
  573.                 $names = `textScrollList -q -si EEattrList`;
  574.                 $attrName = $names[0];
  575.             }
  576.             else 
  577.             {
  578.                 warning ("Expression Editor: name "+$attrName+" is not an attribute of object "+$nodeName+".");
  579.             }
  580.         }
  581.         else if (EEnodeIsInList($nodeName) > -1)
  582.         {
  583.             // User typed an object, and it is in the object list.  So
  584.             // make it selected, and build its attribute list.  Then
  585.             // make the newly typed attribute selected, if it's a 
  586.             // valid attribute name.
  587.             //
  588.             EEnewSelectedNode($nodeName);
  589.  
  590.             if ((($attrListIndex = EEattrIsInList($attrName)) > -1) ||
  591.                 (($attrListIndex = EEgetAttrFromNode($attrName)) > -1))
  592.             {
  593.                 EEnewSelectedAttr($attrListIndex);
  594.                 $names = `textScrollList -q -si EEattrList`;
  595.                 $attrName = $names[0];
  596.             }
  597.             else 
  598.             {
  599.                 warning ("Expression Editor: name "+$attrName+" is not an attribute of object "+$nodeName+".");
  600.             }
  601.         }
  602.         else 
  603.         {
  604.             // User typed an object name that's not in the object list. 
  605.             // If it's a valid object, reset filter to all dag objs or
  606.             // dep nodes (for consistency in lists), rebuild the object
  607.             // list, make the new object selected, and build its
  608.             // attribute list.
  609.             //
  610.             if (EEisValidNodeName($nodeName))
  611.             {
  612.                 EEresetFilterToAll($nodeName);
  613.                 EEnewSelectedNode($nodeName);
  614.                 if (($attrListIndex = EEattrIsInList($attrName)) > -1)
  615.                 {
  616.                     EEnewSelectedAttr($attrListIndex);
  617.                     $names = `textScrollList -q -si EEattrList`;
  618.                     $attrName = $names[0];
  619.                 }
  620.                 else 
  621.                 {
  622.                     warning ("Expression Editor: "+$attrName+" is not an attribute of "+$nodeName+".");
  623.                 }
  624.             }
  625.         }
  626.     }
  627.  
  628.     // Re-write the textfield to make sure the long attribute name is 
  629.     // in it.
  630.     //
  631.     if (size($attrName) > 0)
  632.     {
  633.         string $newString = $nodeName+"."+$attrName;
  634.         textFieldGrp -e -tx $newString  EEselNameT;
  635.     }
  636.  
  637.     clear($buffer);
  638.     clear($currentAttrs);
  639.     clear($nodeNames);
  640.  
  641. }    // EEselectedNodeAttrCB
  642.  
  643.  
  644.  
  645. //  ================ EEnewExpressionCB ================
  646. //
  647. //  SYNOPSIS
  648. //      Called when the "New Expression" button is selected.
  649. //
  650. global proc EEnewExpressionCB(int $launchEditor)
  651. {
  652.     global string $EEnodeMode;
  653.     global int $EEobjIsParticle;
  654.     global int $EEcurrentEditor;
  655.     global int $EEdoLaunchTextEd;
  656.  
  657.     string $currObjAttr;
  658.     string $buffer[];
  659.  
  660.     if ( $EEobjIsParticle)
  661.         $currObjAttr = `textFieldGrp -q -tx EEselNameT`;
  662.     else
  663.         $currObjAttr = `textFieldGrp -q -tx EEdefNameT`;
  664.  
  665.     tokenize($currObjAttr, ".", $buffer);
  666.  
  667.     if ($EEnodeMode == "object")
  668.     {
  669.         // If in object mode and the current selected attribute already
  670.         // is connected to an expression, then the new expression will
  671.         // be unrelated to it, so deselect it.
  672.         //
  673.         string $expression = `scrollField -q -text EEmultiText`;
  674.         if (size($expression) > 0)
  675.             textScrollList -e -da EEattrList;
  676.     }
  677.     else
  678.     {
  679.         textScrollList -e -da EEnodeList;
  680.     }
  681.  
  682.     if ($EEcurrentEditor != 1 && $launchEditor)
  683.         $EEdoLaunchTextEd = 1;
  684.  
  685.     EEdisplayNoExpression($buffer[0]);
  686.  
  687. }    // EEnewExpressionCB
  688.  
  689.  
  690. //  ================ EEdeleteCB ================
  691. //
  692. //  SYNOPSIS
  693. //      Delete the expression in the editor.
  694. //
  695. //
  696. global proc EEdeleteCB()
  697. {
  698.     global int $EEobjIsParticle;
  699.     global int $EEisRuntime;
  700.     global string $EEnodeMode;
  701.     global int $EEcreateMode;
  702.  
  703.     if ($EEcreateMode)
  704.     {
  705.         warning "Expression Editor: In create mode; there's nothing to delete.";
  706.         return;
  707.     }
  708.  
  709.     // Delete the expression.
  710.     //
  711.     if ($EEobjIsParticle)
  712.     {
  713.         // To delete a particle expression, just blank it out.
  714.         //
  715.         string $objAttrName = `textFieldGrp -q -tx EEselNameT`;
  716.         string $buffer[];
  717.         tokenize($objAttrName, ".", $buffer);
  718.         string $nodeName = $buffer[0];
  719.         string $attrName = $buffer[1];
  720.  
  721.         EEdynExpressionCmd($EEisRuntime, "", $nodeName);
  722.     }
  723.     else
  724.     {
  725.         // Get the expression name, and call delete on it.
  726.         //
  727.         string $exprName = `textField -q -tx EEexprNameT`;
  728.         evalEcho("delete "+$exprName);
  729.     }
  730.  
  731.     // Re-set to new expression mode
  732.     //
  733.     EEnewExpressionCB(0);
  734.  
  735. }    // EEdeleteCB
  736.  
  737. //  ================ EEnodeListCB ================
  738. //
  739. //  SYNOPSIS
  740. //      Something in the scrolled text list of nodes is selected.
  741. //
  742. global proc EEnodeListCB()
  743. {
  744.     global string $EEcurrSelectedNode;
  745.     global string $EEnodeMode;
  746.     global int $EEobjIsParticle;
  747.     global int $EEdoLaunchTextEd;
  748.     global int $EEpExpressionInEditor;
  749.     global int $EEexpressionInEditor;
  750.  
  751.     string $nodeName[];
  752.  
  753.     $nodeName = `textScrollList -q -si EEnodeList`;
  754.  
  755.     // Here and below have to take into account that the user may
  756.     // have clicked (esp. double-clicked) on the node that is 
  757.     // currently already in the editor.  In that case, the only
  758.     // thing that needs to be done is launch a text editor, if the
  759.     // the user double-clicked.
  760.     //
  761.     if ($nodeName[0] != $EEcurrSelectedNode)
  762.     {
  763.         // Stop the attribute changed message for the previous selection.
  764.         //
  765.         if (size($EEcurrSelectedNode) > 0)
  766.             expressionEditorListen -sla $EEcurrSelectedNode;
  767.  
  768.         // Whatever text editor file may have been for the current
  769.         // expression, it isn't now, because a new node was selected.
  770.         //
  771.         $EEpExpressionInEditor = -1;
  772.         $EEexpressionInEditor = -1;
  773.  
  774.         // Start the attribute changed message for the new selection
  775.         //
  776.         expressionEditorListen -la $nodeName[0];
  777.     }
  778.  
  779.     if (EEisParticle($nodeName[0]))
  780.     {
  781.         $EEobjIsParticle = 1;
  782.         EEparticleListChanged($nodeName[0]);
  783.     }
  784.     else
  785.     {
  786.         $EEobjIsParticle = 0;
  787.         if ($EEnodeMode == "object")
  788.             EEobjectListChanged($nodeName[0]);
  789.         else if ($EEnodeMode == "scriptNode")
  790.         {
  791.             attrEnumOptionMenu -e 
  792.                 -at ($nodeName[0] + ".scriptType") EEscriptNodeTypeAOM;
  793.  
  794.             EEscriptListChanged($nodeName[0]);
  795.         }
  796.         else
  797.             EEexpressionListChanged($nodeName[0]);
  798.     }
  799.  
  800.     $EEcurrSelectedNode = $nodeName[0];
  801.     $EEdoLaunchTextEd = 0;
  802.  
  803.     clear ($nodeName);
  804.  
  805. }    // EEnodeListCB
  806.  
  807.  
  808. //  ================ EEnodeListDblClickCB ================
  809. //
  810. //  SYNOPSIS
  811. //      Something in the scrolled text list of nodes is selected with
  812. //        double click
  813. //
  814. global proc EEnodeListDblClickCB()
  815. {
  816.     global int $EEdoLaunchTextEd;
  817.  
  818.     $EEdoLaunchTextEd = 1;
  819.  
  820.     EEnodeListCB();
  821.  
  822. }    // EEnodeListDblClickCB
  823.  
  824.  
  825. //  ================ EEattrListCB ================
  826. //
  827. //  SYNOPSIS
  828. //      Something in the scrolled text list of attributes is selected.
  829. //
  830. global proc EEattrListCB()
  831. {
  832.     global int $EEobjIsParticle;
  833.     global int $EEcurrentEditor;
  834.     global int $EEdoLaunchTextEd;
  835.  
  836.     string $nodeName[], $attrName[];
  837.  
  838.     // Get the newly selected attribute name, and the current object
  839.     // name in the list, and load them.
  840.     //
  841.     $attrName = `textScrollList -q -si EEattrList`;
  842.     $nodeName = `textScrollList -q -si EEnodeList`;
  843.  
  844.     EEloadNewNodeAttr($nodeName[0], $attrName[0]);
  845.  
  846. }    // EEattrListCB
  847.  
  848.  
  849. //  ================ EEattrListDblClickCB ================
  850. //
  851. //  SYNOPSIS
  852. //      Something in the scrolled text list of attributes is selected
  853. //        with double click.
  854. //
  855. global proc EEattrListDblClickCB()
  856. {
  857.     global int $EEdoLaunchTextEd;
  858.     string $nodeName[], $attrName[];
  859.  
  860.     $EEdoLaunchTextEd = 1;
  861.  
  862.     EEattrListCB();
  863.  
  864. }    // EEattrListDblClickCB
  865.  
  866.  
  867. //  ================ EEselectFilterCB ================
  868. //
  869. //  SYNOPSIS
  870. //      Called when the "Select Filter" menu is changed.
  871. //
  872. global proc EEselectFilterCB(string $whichMethod)
  873. {
  874.     // Set up the requested layout.
  875.     //
  876.     EEswitchSelectLayout($whichMethod);
  877.  
  878.     EErebuildNodeList($whichMethod);
  879.  
  880.     if ($whichMethod == "object")
  881.          button -e -enable false EEnewExpButton;
  882.     else    
  883.          button -e -enable true EEnewExpButton;
  884.  
  885. }    // EEselectFilterCB
  886.  
  887.  
  888. //  ================ EEobjFilterCB ================
  889. //
  890. //  SYNOPSIS
  891. //      Called when the Object Filter menu is changed.
  892. //
  893. global proc EEobjFilterCB(string $whichFilter)
  894. {
  895.     global string $EEnodeMode;
  896.     global string $EEcurrNodeFilter;
  897.  
  898.     $EEcurrNodeFilter = $whichFilter;
  899.  
  900.     if ($EEnodeMode == "object")
  901.         EErebuildNodeList($EEnodeMode);
  902.  
  903. }    // EEobjFilterCB
  904.  
  905.  
  906. //  ================ EEattrFilterCB ================
  907. //
  908. //  SYNOPSIS
  909. //      Called when the Attribute Filter menu is changed.
  910. //
  911. global proc EEattrFilterCB(string $whichFilter)
  912. {
  913.     global string $EEnodeMode;
  914.     global string $EEcurrAttrFilter;
  915.  
  916.     $EEcurrAttrFilter = $whichFilter;
  917.  
  918.     if ($EEnodeMode == "object")
  919.     {
  920.         // Rebuild the attribute list if there is a selected
  921.         // object in the object list.  If there was a selected
  922.         // attribute in the list and it is still in the list,
  923.         // make it selected again.
  924.         //
  925.         string $selAttr[] = `textScrollList -q -si EEattrList`;
  926.         string $selObj[] = `textScrollList -q -si EEnodeList`;
  927.  
  928.         if (size($selObj[0]) > 0) 
  929.             EErebuildAttrList($selObj[0]);
  930.  
  931.         if (size($selAttr[0]) > 0)
  932.         {
  933.             if (EEattrIsInList($selAttr[0]) > -1)
  934.                 textScrollList -e -si $selAttr[0] EEattrList;
  935.         }
  936.     }
  937.  
  938. }    // EEattrFilterCB
  939.  
  940.  
  941. //  ================ EEeditorCB ================
  942. //
  943. //  SYNOPSIS
  944. //      Called when the Editor Type option menu is changed.
  945. //
  946. global proc EEeditorCB()
  947. {
  948.     global int $EEcurrentEditor;
  949.     global int $EEobjIsParticle;
  950.  
  951.     string $buffer[];
  952.     string $winEditor;
  953.     string $theEditor, $theMessage;
  954.  
  955.     int $EEcurrentEditor = `optionMenu -q -sl EEeditorOM`; 
  956.  
  957.     if (`about -irix`)
  958.     {
  959.         switch($EEcurrentEditor)
  960.         {
  961.             case 1:    $theEditor = "Expression";
  962.                     break;
  963.             case 2:    $theEditor = "jot";
  964.                     break;
  965.             case 3:    $theEditor = "vi";
  966.                     break;
  967.             case 4:    $theEditor = "vim";
  968.                     break;
  969.             case 5:    $theEditor = "xemacs";
  970.                     break;
  971.             case 6:    $theMessage = EEgetEditorMessage();
  972.                     $winEditor = getenv("WINEDITOR");
  973.                     if (size($winEditor) == 0)
  974.                         $theMessage = 
  975.                             $theMessage + "Currently \"WINEDITOR\" is not set.";
  976.                     else
  977.                         $theMessage = 
  978.                             $theMessage + "\"WINEDITOR\" is now set to \"" + $winEditor + "\".";
  979.                     EEpostConfirm($theMessage);
  980.                     if (size($winEditor) > 0)
  981.                     {
  982.                         tokenize($winEditor, " ", $buffer);
  983.                         $theEditor = $buffer[0];
  984.                     }
  985.                     else
  986.                     {
  987.                         warning ("Expression Editor: To use \"Other\" editor, set \"WINEDITOR\"");
  988.                         optionMenu -e -sl 1 EEeditorOM;
  989.                         scrollField -e -enable true EEmultiText;
  990.                         return;
  991.                     }
  992.                     break;
  993.         }
  994.     }
  995.     if (`about -linux`)
  996.     {
  997.         switch($EEcurrentEditor)
  998.         {
  999.             case 1:    $theEditor = "Expression";
  1000.                     break;
  1001.             case 2:    $theEditor = "emacs";
  1002.                     break;
  1003.             case 3:    $theEditor = "gvim";
  1004.                     break;
  1005.             case 4:    $theEditor = "vi";
  1006.                     break;
  1007.             case 5:    $theEditor = "vim";
  1008.                     break;
  1009.             case 6:    $theEditor = "xedit";
  1010.                     break;
  1011.             case 7:    $theEditor = "xemacs";
  1012.                     break;
  1013.             case 8:    $theMessage = EEgetEditorMessage();
  1014.                     $winEditor = getenv("WINEDITOR");
  1015.                     if (size($winEditor) == 0)
  1016.                         $theMessage = 
  1017.                             $theMessage + "Currently \"WINEDITOR\" is not set.";
  1018.                     else
  1019.                         $theMessage = 
  1020.                             $theMessage + "\"WINEDITOR\" is now set to \"" + $winEditor + "\".";
  1021.                     EEpostConfirm($theMessage);
  1022.                     if (size($winEditor) > 0)
  1023.                     {
  1024.                         tokenize($winEditor, " ", $buffer);
  1025.                         $theEditor = $buffer[0];
  1026.                     }
  1027.                     else
  1028.                     {
  1029.                         warning ("Expression Editor: To use \"Other\" editor, set \"WINEDITOR\"");
  1030.                         optionMenu -e -sl 1 EEeditorOM;
  1031.                         scrollField -e -enable true EEmultiText;
  1032.                         return;
  1033.                     }
  1034.                     break;
  1035.         }
  1036.     }
  1037.  
  1038.     // First test that the editor exists in the user's path.  If
  1039.     // it doesn't, send a message and revert to the Expression
  1040.     // Editor.
  1041.     //
  1042.     if ($EEcurrentEditor == 1)
  1043.     {
  1044.         // User is switching back to edit in the Expression Editor:
  1045.         // Check that the current expression is not already in a
  1046.         // text editor.  If it is, don't switch, and warn the user
  1047.         // to dismiss the text editor first.
  1048.         //
  1049.         string $expressionName = `textField -q -text EEexprNameT`;
  1050.         int $index = -1;
  1051.         if (size($expressionName))
  1052.         {
  1053.             if ($EEobjIsParticle)
  1054.             {
  1055.                 if (size($expressionName))
  1056.                     $index = EEexpressionIsInTextEditor($expressionName, 1);
  1057.             }
  1058.             else
  1059.             {
  1060.                 if (size($expressionName))
  1061.                     $index = EEexpressionIsInTextEditor($expressionName, 0);
  1062.             }
  1063.             if ($index > -1)
  1064.             {
  1065.                 // The current expression is in a text editor.
  1066.                 //
  1067.                 warning("The current expression is in a text editor.");
  1068.  
  1069.             }
  1070.         }
  1071.         if ($index > -1)
  1072.             scrollField -e -enable false EEmultiText;
  1073.         else
  1074.             scrollField -e -enable true EEmultiText;
  1075.     }
  1076.  
  1077. }    // EEeditorCB
  1078.  
  1079.  
  1080. //  ================ EErulesCB ================
  1081. //
  1082. //  SYNOPSIS
  1083. //      Called when the rules radio button is changed.
  1084. //
  1085. global proc EErulesCB(string $whichRule)
  1086. {
  1087.     global int $EEisRuntime;
  1088.     string $EEnodeMode;
  1089.     string $particleExpr;
  1090.  
  1091.     string $objAttrName = `textFieldGrp -q -tx EEselNameT`;
  1092.     string $buffer[];
  1093.     tokenize($objAttrName, ".", $buffer);
  1094.  
  1095.     int $whichButton = `radioButtonGrp -q -sl EErulesRBG`;
  1096.  
  1097.     if ($whichButton == 1)
  1098.         $EEisRuntime = 1;
  1099.     else
  1100.         $EEisRuntime = 0;
  1101.  
  1102.     $particleExpr = EEgetParticleExpression($buffer[0], "");
  1103.  
  1104.     if (size($particleExpr) > 0)
  1105.     {
  1106.         scrollField -e -tx $particleExpr EEmultiText;
  1107.         EEsetEditMode("Editing ParticleExpression");
  1108.     }
  1109.     else
  1110.     {
  1111.         scrollField -e -tx "" EEmultiText;
  1112.         EEsetCreateMode("Creating Particle Expression");
  1113.     }
  1114.  
  1115.     // Putting a new expression in the editor, so enable multiText
  1116.     // if the expression is not already in a file.
  1117.     //
  1118.     int $index = EEexpressionIsInTextEditor($buffer[0], 1);
  1119.     if ($index == -1)
  1120.         scrollField -e -enable true EEmultiText;
  1121.     else
  1122.         scrollField -e -enable false EEmultiText;
  1123.  
  1124. }    // EErulesCB
  1125.  
  1126. //  ================ EEmathFuncCB ================
  1127. //
  1128. //  SYNOPSIS
  1129. //      Called when the math function is selected
  1130. //
  1131. global proc EEmathFuncCB(int $index)
  1132. {
  1133.     global    string $EEMathFunction[];
  1134.  
  1135.     scrollField -e -it $EEMathFunction[$index] EEmultiText;
  1136.     textField -e -tx $EEMathFunction[$index+1] EEhelpField;
  1137.  
  1138. }    // EEmathFuncCB
  1139.  
  1140. //  ================ EEvectFuncCB ================
  1141. //
  1142. //  SYNOPSIS
  1143. //      Called when the vector function is selected
  1144. //
  1145. global proc EEvectFuncCB(int $index)
  1146. {
  1147.     global    string $EEVectorFunction[];
  1148.  
  1149.     scrollField -e -it $EEVectorFunction[$index] EEmultiText;
  1150.     textField -e -tx $EEVectorFunction[$index+1] EEhelpField;
  1151.  
  1152. }    // EEvectFuncCB
  1153.  
  1154. //  ================ EEconvFuncCB ================
  1155. //
  1156. //  SYNOPSIS
  1157. //      Called when the conversion function is selected 
  1158. //
  1159. global proc EEconvFuncCB(int $index)
  1160. {
  1161.     global    string $EEConversionFunction[];
  1162.  
  1163.     scrollField -e -it $EEConversionFunction[$index] EEmultiText;
  1164.     textField -e -tx $EEConversionFunction[$index+1] EEhelpField;
  1165.  
  1166. }    // EEconvFuncCB
  1167.  
  1168. //  ================ EEarrayFuncCB ================
  1169. //
  1170. //  SYNOPSIS
  1171. //      Called when the array function is selected 
  1172. //
  1173. global proc EEarrayFuncCB(int $index)
  1174. {
  1175.     global    string $EEArrayFunction[];
  1176.  
  1177.     scrollField -e -it $EEArrayFunction[$index] EEmultiText;
  1178.     textField -e -tx $EEArrayFunction[$index+1] EEhelpField;
  1179.  
  1180. }    // EEarrayFuncCB
  1181.  
  1182. //  ================ EErandFuncCB ================
  1183. //
  1184. //  SYNOPSIS
  1185. //      Called when the random function is selected 
  1186. //
  1187. global proc EErandFuncCB(int $index)
  1188. {
  1189.     global    string $EERandomFunction[];
  1190.  
  1191.     scrollField -e -it $EERandomFunction[$index] EEmultiText;
  1192.     textField -e -tx $EERandomFunction[$index+1] EEhelpField;
  1193.  
  1194. }    // EErandFuncCB
  1195.  
  1196. //  ================ EEcurveFuncCB ================
  1197. //
  1198. //  SYNOPSIS
  1199. //      Called when the curve function is selected 
  1200. //    This block has distinct elements for the menu label
  1201. //    (the first string in each set)
  1202. //    and the literal string to insert in the expression (the second)
  1203. //    in order to distinguish between the 2 overloaded
  1204. //    versions of hermite().
  1205. //
  1206. global proc EEcurveFuncCB(int $index)
  1207. {
  1208.     global    string $EECurveFunction[];
  1209.  
  1210.     scrollField -e -it $EECurveFunction[$index+1] EEmultiText;
  1211.     textField -e -tx $EECurveFunction[$index+2] EEhelpField;
  1212.  
  1213. }    // EEcurveFuncCB
  1214.  
  1215.  
  1216. // ******************************************************************
  1217. //
  1218. //                    EXPRESSION EDITOR MESSAGE CALLBACKS
  1219. //
  1220. //   These procs are called from TexprEdListenAction.cc, when
  1221. //   messages are received that there are active list or database
  1222. //     changes
  1223. //
  1224. //  ================ EEactiveListChanged ================
  1225. //
  1226. //  SYNOPSIS
  1227. //      The active (selection) list has changed. So update the
  1228. //        object list.
  1229. //
  1230. //
  1231. global proc EEactiveListChanged()
  1232. {
  1233.     global string $EEnodeMode;
  1234.     global string $EEcurrNodeFilter;
  1235.  
  1236.     // If the current filter is "allSelected", rebuild the
  1237.     // list.  (If not "allSelected", no need to change.  Messages that
  1238.     // objects have been added/removed are handled elsewhere.
  1239.     //
  1240.     if (`window -exists "expressionEditorWin"`)
  1241.     {
  1242.         if ($EEnodeMode == "object" && $EEcurrNodeFilter == "allSelected")
  1243.         {
  1244.             EErebuildNodeList($EEnodeMode);
  1245.         }
  1246.     }
  1247. }    // EEactiveListChanged
  1248.  
  1249.  
  1250. //  ================ EEnodeAdded ================
  1251. //
  1252. //  SYNOPSIS
  1253. //      A node has been added to the scene.  Update the
  1254. //        object/attribute list, if needed.
  1255. //
  1256. //
  1257. global proc EEnodeAdded(string $nodeName)
  1258. {
  1259.     global string $EEnodeMode;
  1260.     global string $EEcurrNodeFilter;
  1261.  
  1262.     if (!`window -exists "expressionEditorWin"`)
  1263.     {
  1264.         return;
  1265.     }
  1266.  
  1267.     string $nodeList[];
  1268.     int $i;
  1269.  
  1270.     // If the new node is a particle or expression, we have to register
  1271.     // to listen for creation/deletion of expressions.
  1272.     //
  1273.     if (EEisParticle($nodeName) || EEisExpression($nodeName))
  1274.          expressionEditorListen -le $nodeName;
  1275.  
  1276.     // If in expression mode, get the name of all expressions.
  1277.     // If in object mode, get the name of all objects of the type 
  1278.     // that is currently being displayed.  If the new node is in
  1279.     // the list, add it to the text scroll list.  
  1280.     //
  1281.     if ($EEnodeMode == "expression")
  1282.     {
  1283.         $nodeList = EEgetExpressionList();
  1284.     } 
  1285.     else if ($EEnodeMode == "scriptNode") 
  1286.     {
  1287.         $nodeList = EEgetCurrTypeList("scriptNode");
  1288.     }
  1289.     else
  1290.     {
  1291.         $nodeList = EEgetCurrTypeList($EEcurrNodeFilter);
  1292.     }
  1293.  
  1294.     for ($i = 0; $i < size($nodeList); $i++)
  1295.     {
  1296.         if ($nodeName == $nodeList[$i])
  1297.         {
  1298.             EEaddNodeToList($nodeName);
  1299.             break;
  1300.         }
  1301.     }
  1302.  
  1303.     // If in object mode and a new expression node has been created,
  1304.     // and it has been connected to the currently selected object.attr,
  1305.     // then load it into the editor.
  1306.     //
  1307.     if ($EEnodeMode == "object" && EEisExpression($nodeName)) 
  1308.     {
  1309.         // Get the selected obj.attr.  If there is one, and it is
  1310.         // connected to nodeName, then display the expression
  1311.         //
  1312.         string $selectedNode[] = `textScrollList -q -si EEnodeList`;
  1313.         string $selectedAttr[] = `textScrollList -q -si EEattrList`;
  1314.         if (size($selectedNode) && size($selectedAttr))
  1315.         {
  1316.             string $objAttr = $selectedNode[0] +"."+$selectedAttr[0];
  1317.  
  1318.             string $exprName[] = 
  1319.                 `listConnections -s true -d false -t "expression" -scn true $objAttr`;
  1320.  
  1321.             // If the obj.attr is connected to the expression node, 
  1322.             // load it.
  1323.             //
  1324.             if ($exprName[0] == $nodeName)
  1325.                 EEdisplayExpression($objAttr);
  1326.         }
  1327.     }
  1328.  
  1329. }    // EEnodeAdded
  1330.  
  1331.  
  1332. //  ================ EEnodeRemoved ================
  1333. //
  1334. //  SYNOPSIS
  1335. //      A node has been removed from the scene.  Remove it
  1336. //        from the object/attribute list, if needed.
  1337. //
  1338. //
  1339. global proc EEnodeRemoved(string $nodeName)
  1340. {
  1341.     global string $EEnodeMode;
  1342.     global int $EEobjIsParticle;
  1343.  
  1344.     if (!`window -exists "expressionEditorWin"`)
  1345.     {
  1346.         return;
  1347.     }
  1348.  
  1349.     string $objectList[] = `textScrollList -q -ai EEnodeList`;
  1350.  
  1351.     // If the node is a particle or expression, unregister it to receive
  1352.     // expression changed messages.
  1353.     //
  1354.     if (EEisParticle($nodeName) || EEisExpression($nodeName))
  1355.          expressionEditorListen -sle $nodeName;
  1356.  
  1357.     // If the deleted node is in the list, remove it.  If it
  1358.     // is the selected node, clear the attribute list, and
  1359.     // make nothing selected in the node list.
  1360.     //
  1361.     int $i;
  1362.     int $nodeWasInList = 0;
  1363.     for($i = 0; $i < size($objectList); $i++)
  1364.     {
  1365.         if ($nodeName == $objectList[$i])
  1366.         {
  1367.             string $selected[] = `textScrollList -q -si EEnodeList`;
  1368.             EEremoveNodeFromList($nodeName, 1);
  1369.             $nodeWasInList = 1;
  1370.             if ($nodeName == $selected[0])
  1371.             {
  1372.                 textScrollList -e -ra EEattrList;
  1373.  
  1374.                 // At this point nothing is selected, so put the editor
  1375.                 // in create non-particle mode (non-particle so the user
  1376.                 // can use the "New Expression" button.)
  1377.                 //
  1378.                 EEclearAllControls();
  1379.                 if ($EEobjIsParticle)
  1380.                 {
  1381.                     $EEobjIsParticle = 0;
  1382.                     if ($EEnodeMode == "scriptNode") 
  1383.                     {
  1384.                         EEsetCreateMode("Creating Script Node");
  1385.                     } 
  1386.                     else 
  1387.                     {
  1388.                         EEsetCreateMode("Creating Expression");
  1389.                     }
  1390.                     EEswitchRulesForm(0);
  1391.                     textFieldGrp -e -tx "" -enable true EEdefNameT;
  1392.                     text -e -enable true EEexprNameLabel;
  1393.                 }
  1394.             }
  1395.             break;
  1396.         }
  1397.     }
  1398.     // If the node was not in the node list, it could still, if it
  1399.     // was an expression, have been connected to the current obj.attr.
  1400.     // So, if in object mode and the node just deleted was an expression,
  1401.     // if it is in the editor, remove it.
  1402.     //
  1403.     // NEW
  1404.     if (!$nodeWasInList &&
  1405.         EEisExpression($nodeName)  &&
  1406.         $EEnodeMode == "object")
  1407.     {
  1408.         string $exprName = `textField -q -tx EEexprNameT`;
  1409.         if ($exprName == $nodeName)
  1410.             EEdisplayNoExpression($nodeName);
  1411.     }
  1412.  
  1413. }    // EEnodeRemoved
  1414.  
  1415.  
  1416. //  ================ EEnodeNameChanged ================
  1417. //
  1418. //  SYNOPSIS
  1419. //      The name of a node has been changed, so reflect the change
  1420. //        in the list.
  1421. //
  1422. //
  1423. global proc EEnodeNameChanged(string $oldNodeName, string $newNodeName)
  1424. {
  1425.     global string $EEnodeMode;
  1426.  
  1427.     if (!`window -exists "expressionEditorWin"`)
  1428.         return;
  1429.  
  1430.     // Find the old name in the object list, get its index, and find out if it 
  1431.     // is selected.
  1432.     // Remove the old name from the list and add the new name in the same spot
  1433.     // If it is selected, select it and change the name in the selected object
  1434.     // textfield, and the default textfield if it is there.
  1435.     //
  1436.     string $nodeList[] = `textScrollList -q -ai EEnodeList`;
  1437.     int $selected[] = `textScrollList -q -sii EEnodeList`;
  1438.     int $renamedNode;
  1439.  
  1440.     int $i;
  1441.     for ($i = 0; $i < size($nodeList); $i++)
  1442.     {
  1443.         if ($oldNodeName == $nodeList[$i])
  1444.         {
  1445.             // Found the old node name in the scrolled list of nodes.
  1446.             // So remove it, and replace it with the new name.
  1447.             //
  1448.             int $index = $i + 1;
  1449.             textScrollList -e -rii $index EEnodeList;
  1450.             textScrollList -e -ap $index $newNodeName EEnodeList;
  1451.             if ($selected[0] == $index)
  1452.             {
  1453.                 // The renamed node is the one selected in the list, so now
  1454.                 // select the new name, and put it in the Expression Name
  1455.                 // textfield..
  1456.                 //
  1457.                 textScrollList -e -sii $index EEnodeList;
  1458.  
  1459.                 // If in object mode, reset the selected and default textfields
  1460.                 // if the renamed object is the one selected in the editor.
  1461.                 //
  1462.                 if ($EEnodeMode == "object")
  1463.                 {
  1464.                     string $objAttrName = `textFieldGrp -q -tx EEselNameT`;
  1465.                     string $buffer[];
  1466.                     tokenize($objAttrName, ".", $buffer);
  1467.                     $objAttrName = $newNodeName;
  1468.                     if (size($buffer) == 2)
  1469.                         $objAttrName = $objAttrName + "." + $buffer[1];
  1470.                     textFieldGrp -e -tx $objAttrName EEselNameT;
  1471.                     string $defObjName = `textFieldGrp -q -tx EEdefNameT`;
  1472.                     if (size($defObjName) > 0)
  1473.                         textFieldGrp -e -tx $newNodeName EEdefNameT;
  1474.                 }
  1475.  
  1476.                 if ($EEnodeMode == "scriptNode")
  1477.                 {
  1478.                     textFieldGrp -e -tx $newNodeName EEselNameT;
  1479.                 }
  1480.             }
  1481.         }
  1482.     }
  1483.  
  1484.     // If the new node name is an expression name and is currently
  1485.     // in the Expression Name textfield, then put the new name in
  1486.     // the field.
  1487.     //
  1488.     string $currExprName = `textField -q -tx EEexprNameT`;
  1489.  
  1490.     if ($oldNodeName == $currExprName)
  1491.     {
  1492.         textField -e -tx $newNodeName EEexprNameT;
  1493.     }
  1494.  
  1495. }    // EEnodeNameChanged
  1496.  
  1497.  
  1498. //  ================ EEattributeAdded ================
  1499. //
  1500. //  SYNOPSIS
  1501. //      An attribute has been added to a node.  So add it to
  1502. //        the Attributes list, if this node is selected, and if
  1503. //        the attribute meets the requirements.
  1504. //
  1505. //
  1506. global proc EEattributeAdded(string $nodeName, string $attributeName)
  1507. {
  1508.     if (!`window -exists "expressionEditorWin"`)
  1509.         return;
  1510.  
  1511.     string $selectedNode[] = `textScrollList -q -si EEnodeList`;
  1512.  
  1513.     if ($nodeName == $selectedNode[0])
  1514.     {
  1515.         // If the node is a particle, eliminate a few attributes we
  1516.         // don't want in the editor.
  1517.         //
  1518.         if (EEisParticle($nodeName))
  1519.         {
  1520.             if (EEisValidDynAttr($attributeName))
  1521.                 textScrollList -e -a $attributeName EEattrList;
  1522.         }
  1523.         else
  1524.             textScrollList -e -a $attributeName EEattrList;
  1525.     }
  1526.  
  1527. }    // EEattributeAdded
  1528.  
  1529.  
  1530. //  ================ EEattributeRemoved ================
  1531. //
  1532. //  SYNOPSIS
  1533. //      An attribute has been removed to the node.  So remove it 
  1534. //        from the Attributes list, if this node is selected.
  1535. //
  1536. global proc EEattributeRemoved(string $nodeName, string $attributeName)
  1537. {
  1538.  
  1539.     if (!`window -exists "expressionEditorWin"`)
  1540.         return;
  1541.  
  1542.     string $selectedNode[] = `textScrollList -q -si EEnodeList`;
  1543.     string $selectedAttr[] = `textScrollList -q -si EEattrList`;
  1544.  
  1545.     if ($nodeName == $selectedNode[0])
  1546.     {
  1547.         // Remove the attribute from the list, if it is in the list.
  1548.         //
  1549.         string $listAttrs[] = `textScrollList -q -ai EEattrList`;
  1550.         int $i;
  1551.         for ($i = 0; $i < size($listAttrs); $i++)
  1552.         {
  1553.             if ($listAttrs[$i] == $attributeName)
  1554.             {
  1555.                 textScrollList -e -ri $attributeName EEattrList;
  1556.                 if ($attributeName == $selectedAttr[0])
  1557.                 {
  1558.                     // If the removed attribute was the selected one, clear
  1559.                     // the controls and set the first attribute in the list
  1560.                     // to be selected.
  1561.                     //
  1562.                     EEclearAllControls();
  1563.                     textScrollList -e -sii 1 EEattrList;
  1564.                 }
  1565.                 break;
  1566.             }
  1567.         }
  1568.     }
  1569.  
  1570. }    // EEattributeRemoved
  1571.  
  1572.  
  1573. //  ================ EEexpressionCreated ================
  1574. //
  1575. //  SYNOPSIS
  1576. //      An expression has been created from outside the editor.  
  1577. //        If it's in the editor, reload it.
  1578. //
  1579. //
  1580. global proc EEexpressionCreated(string $expressionName)
  1581. {
  1582.     global int $EEeditedInEditor;
  1583.     global string $EEnodeMode;
  1584.  
  1585.     if (!`window -exists "expressionEditorWin"`)
  1586.         return;
  1587.  
  1588.     if ($EEeditedInEditor)
  1589.     {
  1590.         $EEeditedInEditor = 0;
  1591.         return;
  1592.     }
  1593.  
  1594.     // If the obj.attr this expression is connected to is in the
  1595.     // editor, load it.
  1596.     //
  1597.     if ($EEnodeMode == "object")
  1598.     {
  1599.         string $selectedNode[] = `textScrollList -q -si EEnodeList`;
  1600.         string $selectedAttr[] = `textScrollList -q -si EEattrList`;
  1601.         if (size($selectedNode) && size($selectedAttr))
  1602.         {
  1603.             string $selObjAttr = $selectedNode[0] +"."+$selectedAttr[0];
  1604.             string $objAttr[] = 
  1605.             `listConnections -source false -d true -shapes true -plugs true  -scn true  $expressionName`;
  1606.  
  1607.             if ($selObjAttr == $objAttr[0])
  1608.             {
  1609.                 EEdisplayExpression($expressionName);
  1610.             }
  1611.         }
  1612.     }
  1613.  
  1614. }    // EEexpressionCreated
  1615.  
  1616.  
  1617. //  ================ EEexpressionEdited ================
  1618. //
  1619. //  SYNOPSIS
  1620. //      An expression has been edited from outside the editor.  
  1621. //        If it's in the editor, reload it.
  1622. //
  1623. //
  1624. global proc EEexpressionEdited(string $expressionName)
  1625. {
  1626.     global int $EEeditedInEditor;
  1627.  
  1628.     if (!`window -exists "expressionEditorWin"`)
  1629.         return;
  1630.  
  1631.     if ($EEeditedInEditor)
  1632.     {
  1633.         $EEeditedInEditor = 0;
  1634.         return;
  1635.     }
  1636.  
  1637.     // If the expression is in the editor, reload it.
  1638.     //
  1639.     string $currExprName = `textField -q -tx EEexprNameT`;
  1640.  
  1641.     if ($expressionName == $currExprName)
  1642.     {
  1643.         EEdisplayExpression($expressionName);
  1644.     }
  1645.  
  1646. }    // EEexpressionEdited
  1647.  
  1648.  
  1649. //  ================ EEparticleExpressionCreated ================
  1650. //
  1651. //  SYNOPSIS
  1652. //        Called from TexprEdListenAction.
  1653. //      A particle expression has been created from outside the editor.
  1654. //        If in "Expression" mode, add it to the node list.  If needed,
  1655. //        load the new expression.
  1656. //
  1657. //
  1658. global proc EEparticleExpressionCreated(string $which, string $nodeName)
  1659. {
  1660.     global string $EEnodeMode;
  1661.     global int $EEeditedInEditor;
  1662.  
  1663.     if (!`window -exists "expressionEditorWin"`)
  1664.         return;
  1665.  
  1666.     if ($EEeditedInEditor)
  1667.     {
  1668.         $EEeditedInEditor = 0;
  1669.         return;
  1670.     }
  1671.  
  1672.     // A particle has just had its first expression created.
  1673.     // If in expression mode, add the particle to the node list.
  1674.     // If in object mode and the particle is selected, bring in
  1675.     // its expression, and put the editor in edit mode.
  1676.     //
  1677.     if ($EEnodeMode == "expression" && $which == "first")
  1678.     {
  1679.         EEaddNodeToList($nodeName);
  1680.     }
  1681.     else
  1682.     {
  1683.         string $selected[] = `textScrollList -q -si EEnodeList`;
  1684.         if ($selected[0] == $nodeName)
  1685.         {
  1686.             string $particleExpr = 
  1687.                 EEgetParticleExpression($nodeName, "");
  1688.  
  1689.             if (size($particleExpr) > 0)
  1690.             {
  1691.                 scrollField -e -tx $particleExpr EEmultiText;
  1692.                 EEsetEditMode("Editing ParticleExpression");
  1693.             }
  1694.         }
  1695.     }
  1696.  
  1697. }    // EEparticleExpressionCreated
  1698.  
  1699.  
  1700. //  ================ EEparticleExpressionDeleted ================
  1701. //
  1702. //  SYNOPSIS
  1703. //      A particle expression has been deleted from outside the
  1704. //        expression editor.  If in "Expression" mode, remove it from 
  1705. //        the node list.  If selected, remove it from the expression
  1706. //        textfield and name field.
  1707. //
  1708. //
  1709. global proc EEparticleExpressionDeleted(string $which, string $nodeName)
  1710. {
  1711.     global string $EEnodeMode;
  1712.     global int $EEisRuntime;
  1713.  
  1714.     if (!`window -exists "expressionEditorWin"`)
  1715.         return;
  1716.  
  1717.     string $selected[] = `textScrollList -q -si EEnodeList`;
  1718.  
  1719.     // A particle has just had its last expression deleted.
  1720.     // If in expression mode, remove the particle from the node list.
  1721.     // If in object mode and the particle is selected, delete the
  1722.     // expression, and put the editor in create mode.
  1723.     //
  1724.     if ($EEnodeMode == "expression" && $which == "all")
  1725.     {
  1726.         EEremoveNodeFromList($nodeName, 1);
  1727.         EEclearAllControls();
  1728.     }
  1729.     else
  1730.     {
  1731.         if ($selected[0] == $nodeName)
  1732.         {
  1733.             if (($which == "creation" && !$EEisRuntime) ||
  1734.                 ($which == "runtime" && $EEisRuntime) ||
  1735.                 ($which == "all"))
  1736.             {
  1737.                 EEdisplayNoExpression($nodeName);
  1738.             }
  1739.         }
  1740.     }
  1741.  
  1742. }    // EEparticleExpressionDeleted
  1743.  
  1744.  
  1745. //  ================ EEparticleExpressionEdited ================
  1746. //
  1747. //  SYNOPSIS
  1748. //      A particle expression has been edited from outside the
  1749. //        editor.  If it's in the editor, reload it.
  1750. //
  1751. //
  1752. global proc EEparticleExpressionEdited(string $which, string $nodeName)
  1753. {
  1754.     global int $EEisRuntime;
  1755.     global int $EEeditedInEditor;
  1756.  
  1757.     if (!`window -exists "expressionEditorWin"` )
  1758.         return;
  1759.  
  1760.     if ($EEeditedInEditor)
  1761.     {
  1762.         $EEeditedInEditor = 0;
  1763.         return;
  1764.     }
  1765.  
  1766.     // If the expression is in the editor, reload it.
  1767.     //
  1768.     string $currExprName = `textField -q -tx EEexprNameT`;
  1769.  
  1770.     if ($nodeName == $currExprName)
  1771.     {
  1772.         if (($which == "creation" && !$EEisRuntime) ||
  1773.             ($which == "runtime" && $EEisRuntime))
  1774.         {
  1775.             string $expression = EEgetParticleExpression($nodeName, "");
  1776.  
  1777.             scrollField -e -tx $expression EEmultiText;
  1778.         }
  1779.     }
  1780.  
  1781. }    // EEparticleExpressionEdited
  1782.  
  1783.  
  1784.  
  1785. //  ================ EEclearExpressionEditor ================
  1786. //
  1787. //  SYNOPSIS
  1788. //      Clear the editor.  This is called when there is a file new or file
  1789. //        open, after the old scene has been removed, so we want to clear the
  1790. //        editor, but not try to remove client messages.  But we do need to
  1791. //        clear up FAM connections if the user has left an external test editor
  1792. //        up.
  1793. //
  1794. global proc EEclearExpressionEditor()
  1795. {
  1796.     global string $EEorigExpressionName;
  1797.     global string $EEcurrExpressionName;
  1798.     global string $EEcurrSelectedNode;
  1799.     global string $EEnodeMode;
  1800.  
  1801.     global int $EEpExpressionInEditor;
  1802.     global int $EEexpressionInEditor;
  1803.     global int $EEobjIsParticle;
  1804.  
  1805.     global string $EEcurrFiles[];
  1806.     global string $EEcurrFileExprName[];
  1807.     global int    $EEcurrFileCreateMode[];   // 1 = creating; 0 = editing
  1808.     global string $EEcurrFileDefObj[];
  1809.     global string $EEcurrParticleFiles[];
  1810.  
  1811.     if (!`window -exists "expressionEditorWin"` )
  1812.         return;
  1813.  
  1814.     // If there are editors left up with files from the scene being deleted,
  1815.     // delete the expression file to force call to FAM to clean up.  This will
  1816.     // not take down the editor, but it will at least disconnect it from FAM,
  1817.     // since its contents are not longer in the scene.  Note too that this
  1818.     // will delete the edit file but not the .EXE file.  It can't be fully
  1819.     // removed because if the editor is up, it is a running process, and FAM
  1820.     // doesn't get called.  So here delete the expression file through normal
  1821.     // channels, which will break its FAM connection and clean up the EE
  1822.     // internal structures. When the user does dismiss the external text editor,
  1823.     // the .EXE file will get removed and FAM will be called to disconnect it
  1824.     // from monitoring.
  1825.     //
  1826.     if (size($EEcurrFiles) > 0)
  1827.     {
  1828.         for ($i = 0; $i < size($EEcurrFiles); $i++)
  1829.         {
  1830.             EEdeleteEditorFile($EEcurrFiles[$i]);
  1831.         }
  1832.     }
  1833.  
  1834.     if (size($EEcurrParticleFiles) > 0)
  1835.     {
  1836.         for ($i = 0; $i < size($EEcurrParticleFiles); $i++)
  1837.         {
  1838.             EEdeleteEditorFile($EEcurrParticleFiles[$i]);
  1839.         }
  1840.     }
  1841.  
  1842.     $EEpExpressionInEditor = -1;
  1843.     $EEexpressionInEditor = -1;
  1844.  
  1845.     // Clear the old object and attribute lists.
  1846.     //
  1847.     textScrollList -e -ra EEnodeList;
  1848.     textScrollList -e -ra EEattrList;
  1849.  
  1850.     // Clear the expression name, selected object name, default object name
  1851.     // textfields.
  1852.     //
  1853.     textField -e -tx "" EEexprNameT;
  1854.     textFieldGrp -e -tx "" EEselNameT;
  1855.     textFieldGrp -e -tx "" EEdefNameT;
  1856.  
  1857.     // Clear the expression scrolled text field.
  1858.     //
  1859.     scrollField -e -tx "" EEmultiText;
  1860.  
  1861.     // Reset some buttons.
  1862.     //
  1863.     checkBox -e -v 1 EEanimCBox;
  1864.     radioButtonGrp -e -sl 1 EEunitsRBG;
  1865.  
  1866.     // Set in create mode.
  1867.     //
  1868.     if ($EEnodeMode == "scriptNode")
  1869.         EEsetCreateMode("Creating Script Node");
  1870.     else
  1871.         EEsetCreateMode("Creating Expression");
  1872.  
  1873.     // If in particle expression mode, switch to regular expression mode.
  1874.     //
  1875.     if ($EEobjIsParticle)
  1876.     {
  1877.         $EEobjIsParticle = 0;
  1878.         EEswitchRulesForm(0);
  1879.         text -e -enable true EEexprNameLabel;
  1880.     }
  1881.  
  1882.     $EEcurrSelectedNode = "";
  1883.     $EEcurrExpressionName = "";
  1884.     $EEorigExpressionName = "";
  1885.  
  1886. }    // EEclearExpressionEditor
  1887.  
  1888.  
  1889.  
  1890. //  ================ EEresetExpressionEditor ================
  1891. //
  1892. //  SYNOPSIS
  1893. //      Clear the editor.  This is called when there is a file new or file
  1894. //        open, after the old scene has been removed, so we want to clear the
  1895. //        editor, but not try to remove client messages.  
  1896. //
  1897. global proc EEresetExpressionEditor()
  1898. {
  1899.     global string $EEnodeMode;
  1900.  
  1901.     // Clear the editor;
  1902.     //
  1903.     EEclearExpressionEditor();
  1904.  
  1905.     // Rebuild it if required.
  1906.     //
  1907.     EErebuildNodeList($EEnodeMode);
  1908.  
  1909. }    // EEresetExpressionEditor
  1910.